package cn.tedu.lucky.draw.server.controller;

import cn.tedu.lucky.draw.server.common.annotation.OperationLog;
import cn.tedu.lucky.draw.server.common.result.JsonResult;
import cn.tedu.lucky.draw.server.protocol.po.ActivityRule;
import cn.tedu.lucky.draw.server.protocol.po.Rule;
import cn.tedu.lucky.draw.server.service.IActivityRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class ActivityRuleController {

    @Autowired
    private IActivityRuleService activityRuleService;

    @GetMapping("/draw/activity-rule/findRule/{id}")
    public JsonResult<List<Rule>> findRulesByActivityId(@PathVariable Long id){
        List<Rule> ruleList=activityRuleService.findRulesByActivityId(id);
        return JsonResult.ok(ruleList);
    }

    @GetMapping("/draw/activity-rule/noBindRule/{id}")
    public JsonResult<List<Rule>> findNoBindRule(@PathVariable Long id){
        return JsonResult.ok(activityRuleService.findNoBindRule(id));
    }
    @OperationLog(operation = "绑定活动规则")
    @PostMapping("/draw/activity-rule/save")
    public JsonResult save(@RequestBody List<ActivityRule> activityRuleList){
        activityRuleService.saveAll(activityRuleList);
        return JsonResult.ok();
    }
}
